"""Setup the xrisks application"""
import logging

from paste.deploy import appconfig
from pylons import config

from xrisks.config.environment import load_environment

log = logging.getLogger(__name__)

def setup_config(command, filename, section, vars):
    """Place any commands to setup xrisks here"""
    conf = appconfig('config:' + filename)
    load_environment(conf.global_conf, conf.local_conf)

    from xrisks import model
    model.metadata.drop_all(bind=config['pylons.g'].sa_engine)
    log.info("Creating tables")
    model.metadata.create_all(bind=config['pylons.g'].sa_engine)
    log.info("Successfully setup")

    log.info("Adding data ")
    risk = model.Risk('Risk Name Default', 'Risk Description')
    risk.probability = 1.0
    risk.impact = 10
    model.Session.save(risk)
    model.Session.commit()
    log.info("Successfully added")